package com.dhcc.sds.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsQcentityItemLogEntity;
import com.dhcc.sds.base.service.ISdsQcentityItemLogService;


/**
 * 质控项目操作日志表
 * 
 * @ClassName: SdsQcentityItemLogController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-04-09 10:05:31
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcentityitemlog")
public class SdsQcentityItemLogController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcentityitemlog/";

	@Autowired
	private ISdsQcentityItemLogService sdsQcentityItemLogService;
	

    /**
     * 跳转到质控项目操作日志表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcentityitemlog.html";
    }
	
    /**
     * 跳转到新增质控项目操作日志表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsqcentityitemlog_add.html";
    }
	
	/**
     * 跳转到修改质控项目操作日志表
     */
    @RequestMapping("/to_update/{sdsQcentityItemLogId}")
    public String toUpdate(@PathVariable Long sdsQcentityItemLogId, Model model) {
        SdsQcentityItemLogEntity sdsQcentityItemLog = this.sdsQcentityItemLogService.selectById(sdsQcentityItemLogId);
        model.addAttribute("sdsQcentityItemLog",sdsQcentityItemLog);
        return PREFIX + "sdsqcentityitemlog_edit.html";
    }

    /**
     * 获取质控项目操作日志表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcentityItemLogEntity> page = new PageFactory<SdsQcentityItemLogEntity>().defaultPage();
        List<SdsQcentityItemLogEntity> result = this.sdsQcentityItemLogService.page(page,params);
        page.setRecords((List<SdsQcentityItemLogEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增质控项目操作日志表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcentityItemLogEntity sdsQcentityItemLog) {
        if (CommonUtil.isOneEmpty(sdsQcentityItemLog)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQcentityItemLog.insert();
        return R.ok();
    }

    /**
     * 删除质控项目操作日志表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQcentityItemLogId) {
	
        this.sdsQcentityItemLogService.deleteById(sdsQcentityItemLogId);

        return R.ok();
    }

    /**
     * 修改质控项目操作日志表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQcentityItemLogEntity sdsQcentityItemLog) {
        if (CommonUtil.isOneEmpty(sdsQcentityItemLog)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcentityItemLogEntity old = this.sdsQcentityItemLogService.selectById(sdsQcentityItemLog.getId());

        old.setEntityId(sdsQcentityItemLog.getEntityId());
        old.setEntityItemId(sdsQcentityItemLog.getEntityItemId());
        old.setOperType(sdsQcentityItemLog.getOperType());
        old.setOperTime(sdsQcentityItemLog.getOperTime());
        old.setOperUser(sdsQcentityItemLog.getOperUser());
        old.setOperContent(sdsQcentityItemLog.getOperContent());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
